; parte de este código fue tomado de http://www.richardcunningham.co.uk

GLOBAL getvendorid, getcpuinfo, getbrand


section .bss
vendor_id   resd    12
version     resd    4
features    resd    4
i           resd    4
curfeat     resd    4
brand       resb    48

section .text

names db    'FPU  VME  DE   PSE  TSC  MSR  PAE  MCE  CX8  APIC RESV SEP  MTRR PGE  MCA  CMOV PAT PSE3 PSN  CLFS RESV DS   ACPI MMX FXSR SSE  SSE2 SS   HTT  TM   RESV PBE  '

writeCode       equ 5
video       equ 0xb8000

getvendorid:
    push ebp                        ; construye stack frame
    mov ebp, esp

    mov eax, 0                      ; vendor id
    cpuid
    mov [vendor_id], ebx
    mov [vendor_id+4], edx
    mov [vendor_id+8], ecx

    mov eax, writeCode
    mov edx, 12                     ; longitud del mensaje
    mov ecx, vendor_id              ; mensaje a escribir
    mov ebx, video
    int 0x85

    mov esp, ebp
    pop ebp
    ret

getcpuinfo:
    push ebp                        ; arma stack frame
    mov ebp, esp

    mov eax, 1                      ; cpu info y features
    cpuid
    mov [version], eax
    mov [features], edx

    mov eax, 00000001h
    mov [curfeat], eax
    mov eax,-1
    mov [i], eax

.loop:

    mov eax, [i]
    inc eax
    cmp eax, 31
    jz  .quitloop
    mov [i], eax

    mov ebx, [curfeat]              ; feature actual
    and ebx, [features]             ; fijarse si la feature existe
    mov eax, [curfeat]              ; proxima feature
    shl eax, 1
    mov [curfeat], eax

    cmp ebx, 0                      ; chequear si existia o no
    jz  .loop

    mov eax, [i]
    mov edx, 5
    mov ecx, names
    times 5 add ecx, eax

    push eax
    mov eax, writeCode
    mov ebx, video                      ; "simil file descriptor"
    int 0x85
   
    
    pop eax

    jmp .loop

.quitloop:
    mov esp, ebp
    pop ebp

    ret

getbrand:
    push ebp                        ; arma stack frame
    mov ebp, esp

    mov eax, 80000002h
    cpuid
    mov [brand], eax
    mov [brand+4], ebx
    mov [brand+8], ecx
    mov [brand+12], edx

    mov eax, 80000003h
    cpuid
    mov [brand+16], eax
    mov [brand+20], ebx
    mov [brand+24], ecx
    mov [brand+28], edx

    mov eax, 80000004h
    cpuid
    mov [brand+32], eax
    mov [brand+36], ebx
    mov [brand+40], ecx
    mov [brand+44], edx

    push eax
    mov eax, writeCode
    mov ebx, video
    mov ecx, brand
    mov edx, 48
    int 0x85

    mov esp, ebp
    pop ebp
    ret

